import { ComponentInfo, EditorState } from '@/components/editor';

// 添加新组件
export function insertComponentInfo(
  data: EditorState,
  newComponent: ComponentInfo
) {
  const { selectedId, componentList } = data;

  const index = componentList.findIndex((item) => item.fe_id === selectedId);

  if (index < 0) {
    componentList.push(newComponent);
  } else {
    componentList.splice(index + 1, 0, newComponent);
  }

  data.selectedId = newComponent.fe_id || '';

  return data;
}
